<?php
namespace app\user\controller;
use think\Db;
class Chatroom{
    public function initialize(){

        parent::initialize();

    }
    public function get_balance(){

    	$getArray = input('mobile');

    	$balance = Db::name('users')->where('mobile',$getArray)->field('money_jifen')->find();

    	return $balance['money_jifen'];

    }
    public function set_balance(){

    	$getArray = input();

    	$password = md5(md5(substr($getArray['send_time'], 4)));

    	if($password != $getArray['password']){

    		return json_encode(array('error'=>1,'result'=>'密码错误'));

    	}
    	if($getArray['type'] == 1){

    		if(!Db::name('users')->where(array('mobile'=>$getArray['mobile']))->setInc('money_jifen',$getArray['money'])){

    			return json_encode(array('error'=>1,'result'=>'加款错误'));

    		}


    	}
    	if($getArray['type'] == 2){

    		if(!Db::name('users')->where(array('mobile'=>$getArray['mobile']))->setDec('money_jifen',$getArray['money'])){

    			return json_encode(array('error'=>1,'result'=>'扣款错误'));

    		}


    	}
    	return json_encode(array('error'=>0,'result'=>''));

    }
}